<template>
  <div class="">
    {{message}}
    <!-- <a :href="url">跳转APP</a> -->
  </div>
</template>

<script>
/**
 * 短信入口type
 * 
 * 1 云诊室预约记录
 * 2 云候诊记录
 * 3
 */
export default {
  mounted () {
    // let url = 'mailto://open?type=1&t=' + new Date().getTime()
    this.type = this.$route.query.type || 1
    let url = `nhpwlszyypub://open.bsoft?type=${this.type}&t=${new Date().getTime()}`
    window.location.href = url
    // this.testApp(url)
  },
  data () {
    return {
      // url: 'nhpwlszyypub://open?type=2&t=' + new Date().getTime(),
      type: 1,
      hasApp: true,
      message: '页面跳转中...'
    }
  },
  methods: {
    testApp(url) {
      var timeout, t = 1000;
      setTimeout(function () {
        if (this.hasApp) {
          // alert('安装了app');
        } else {
          this.message = '请先安装APP'
        }
        document.body.removeChild(ifr);
      }, 2000)

      var t1 = Date.now();
      var ifr = document.createElement("iframe");
      ifr.setAttribute('src', url);
      ifr.setAttribute('style', 'display:none');
      document.body.appendChild(ifr);
      timeout = setTimeout(function () {
        var t2 = Date.now();
        if (!t1 || t2 - t1 < t + 100) {
          this.hasApp = false;
        }
      }, t);
    }
  }
}
</script>
